<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserhqcode', validatorRules.purchaserhqcode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliercode', validatorRules.suppliercode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="suppliername" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliername', validatorRules.suppliername]" placeholder="请输入suppliername"></a-input>
        </a-form-item>
        <a-form-item label="生产订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipono', validatorRules.ipono]" placeholder="请输入生产订单编号"></a-input>
        </a-form-item>
        <a-form-item label="产品内部ID号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'insideno', validatorRules.insideno]" placeholder="请输入产品内部ID号"></a-input>
        </a-form-item>
        <a-form-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'deviceno', validatorRules.deviceno]" placeholder="请输入设备编号"></a-input>
        </a-form-item>
        <a-form-item label="生产批次号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productbatchno', validatorRules.productbatchno]" placeholder="请输入生产批次号"></a-input>
        </a-form-item>
        <a-form-item label="产品型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productionmodel', validatorRules.productionmodel]" placeholder="请输入产品型号"></a-input>
        </a-form-item>
        <a-form-item label="生产对象名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'manufacturedname', validatorRules.manufacturedname]" placeholder="请输入生产对象名称"></a-input>
        </a-form-item>
        <a-form-item label="工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processname', validatorRules.processname]" placeholder="请输入工序名称"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categorycode', validatorRules.categorycode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclasscode', validatorRules.subclasscode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processcode', validatorRules.processcode]" placeholder="请输入工序编码"></a-input>
        </a-form-item>
        <a-form-item label="生产工艺路线编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processno', validatorRules.processno]" placeholder="请输入生产工艺路线编码"></a-input>
        </a-form-item>
        <a-form-item label="生产车间id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopid', validatorRules.workshopid]" placeholder="请输入生产车间id"></a-input>
        </a-form-item>
        <a-form-item label="生产车间编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopcode', validatorRules.workshopcode]" placeholder="请输入生产车间编码"></a-input>
        </a-form-item>
        <a-form-item label="生产车间名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'workshopname', validatorRules.workshopname]" placeholder="请输入生产车间名称"></a-input>
        </a-form-item>
        <a-form-item label="生产工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'wono', validatorRules.wono]" placeholder="请输入生产工单编号"></a-input>
        </a-form-item>
        <a-form-item label="实物id，如国网实物id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productid', validatorRules.productid]" placeholder="请输入实物id，如国网实物id"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'datasource', validatorRules.datasource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择来源数据创建时间" v-decorator="[ 'datasourcecreatetime', validatorRules.datasourcecreatetime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="计划开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划开始时间" v-decorator="[ 'planstarttime', validatorRules.planstarttime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="计划结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划结束时间" v-decorator="[ 'planendtime', validatorRules.planendtime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际开始时间" v-decorator="[ 'actualstartdate', validatorRules.actualstartdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际结束时间" v-decorator="[ 'actualfinishdate', validatorRules.actualfinishdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'orderstatus', validatorRules.orderstatus]" placeholder="请输入订单状态"></a-input>
        </a-form-item>
        <a-form-item label="客户所属省份" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerprovince', validatorRules.buyerprovince]" placeholder="请输入客户所属省份"></a-input>
        </a-form-item>
        <a-form-item label="数据拥有方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerid', validatorRules.ownerid]" placeholder="请输入数据拥有方"></a-input>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openid', validatorRules.openid]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="报告批注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'comment', validatorRules.comment]" placeholder="请输入报告批注"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isdeleted', validatorRules.isdeleted]" placeholder="请输入逻辑删除"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="modifytime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modifytime', validatorRules.modifytime]" placeholder="请输入modifytime"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据是新增/更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据是新增/更新"></a-input>
        </a-form-item>
        <a-form-item label="全局流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局流水号"></a-input>
        </a-form-item>
        <a-form-item label="预留字段1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark1', validatorRules.remark1]" placeholder="请输入预留字段1"></a-input>
        </a-form-item>
        <a-form-item label="预留字段2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark2', validatorRules.remark2]" placeholder="请输入预留字段2"></a-input>
        </a-form-item>
        <a-form-item label="预留字段3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark3', validatorRules.remark3]" placeholder="请输入预留字段3"></a-input>
        </a-form-item>
        <a-form-item label="预留字段4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark4', validatorRules.remark4]" placeholder="请输入预留字段4"></a-input>
        </a-form-item>
        <a-form-item label="预留字段5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark5', validatorRules.remark5]" placeholder="请输入预留字段5"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipOperationModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
        purchaserhqcode:{rules: [{ required: true, message: '请输入采购方总部编码!' }]},
        suppliercode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        suppliername:{rules: [{ required: true, message: '请输入suppliername!' }]},
        ipono:{rules: [{ required: true, message: '请输入生产订单编号!' }]},
        insideno:{rules: [{ required: true, message: '请输入产品内部ID号!' }]},
        deviceno:{},
        productbatchno:{rules: [{ required: true, message: '请输入生产批次号!' }]},
        productionmodel:{rules: [{ required: true, message: '请输入产品型号!' }]},
        manufacturedname:{rules: [{ required: true, message: '请输入生产对象名称!' }]},
        processname:{rules: [{ required: true, message: '请输入工序名称!' }]},
        categorycode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclasscode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        processcode:{rules: [{ required: true, message: '请输入工序编码!' }]},
        processno:{},
        workshopid:{},
        workshopcode:{},
        workshopname:{},
        wono:{rules: [{ required: true, message: '请输入生产工单编号!' }]},
        productid:{},
        datasource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        datasourcecreatetime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        planstarttime:{},
        planendtime:{},
        actualstartdate:{},
        actualfinishdate:{},
        orderstatus:{},
        buyerprovince:{rules: [{ required: true, message: '请输入客户所属省份!' }]},
        ownerid:{},
        openid:{},
        comment:{},
        isdeleted:{rules: [{ required: true, message: '请输入逻辑删除!' }]},
        ioflag:{},
        modifytime:{},
        message:{},
        status:{},
        transno:{},
        remark1:{},
        remark2:{},
        remark3:{},
        remark4:{},
        remark5:{},
        },
        url: {
          add: "/eipOperation/add",
          edit: "/eipOperation/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchaserhqcode','suppliercode','suppliername','ipono','insideno','deviceno','productbatchno','productionmodel','manufacturedname','processname','categorycode','subclasscode','processcode','processno','workshopid','workshopcode','workshopname','wono','productid','datasource','datasourcecreatetime','planstarttime','planendtime','actualstartdate','actualfinishdate','orderstatus','buyerprovince','ownerid','openid','comment','isdeleted','ioflag','modifytime','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchaserhqcode','suppliercode','suppliername','ipono','insideno','deviceno','productbatchno','productionmodel','manufacturedname','processname','categorycode','subclasscode','processcode','processno','workshopid','workshopcode','workshopname','wono','productid','datasource','datasourcecreatetime','planstarttime','planendtime','actualstartdate','actualfinishdate','orderstatus','buyerprovince','ownerid','openid','comment','isdeleted','ioflag','modifytime','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>